package com.muyu.danmo.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.danmo.domain.DanmoFamous;
import com.muyu.danmo.domain.DanmoFamousCard;
import com.muyu.danmo.req.DanmoFamousNameReq;
import com.muyu.danmo.req.DanmoSelectFamousCarReq;
import com.muyu.danmo.service.IDanmoFamousCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 名帖字库Controller
 *
 * @author yangle
 * @date 2024-09-23
 */
@RestController
@RequestMapping("/card")
public class DanmoFamousCardController extends BaseController
{
    @Autowired
    private IDanmoFamousCardService danmoFamousCardService;

    /**
     * 查询名帖字库列表
     */
//    @RequiresPermissions("system:card:list")
    @PostMapping("/list")
    public Result list(@RequestBody DanmoFamousCard danmoFamousCard)
    {
        List<DanmoFamousCard> list = danmoFamousCardService.selectDanmoFamousCardList(danmoFamousCard);
        return Result.success(list);
    }

    /**
     * 导出名帖字库列表
     */
//    @RequiresPermissions("system:card:export")
    @Log(title = "名帖字库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoFamousCard danmoFamousCard)
    {
        List<DanmoFamousCard> list = danmoFamousCardService.selectDanmoFamousCardList(danmoFamousCard);
        ExcelUtil<DanmoFamousCard> util = new ExcelUtil<DanmoFamousCard>(DanmoFamousCard.class);
        util.exportExcel(response, list, "名帖字库数据");
    }

    /**
     * 获取名帖字库详细信息
     */
//    @RequiresPermissions("system:card:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoFamousCardService.selectDanmoFamousCardById(id));
    }

    /**
     * 新增名帖字库
     */
//    @RequiresPermissions("system:card:add")
    @Log(title = "名帖字库", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoFamousCard danmoFamousCard)
    {
        return toAjax(danmoFamousCardService.insertDanmoFamousCard(danmoFamousCard));
    }

    /**
     * 修改名帖字库
     */
//    @RequiresPermissions("system:card:edit")
    @Log(title = "名帖字库", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoFamousCard danmoFamousCard)
    {
        return toAjax(danmoFamousCardService.updateDanmoFamousCard(danmoFamousCard));
    }

    /**
     * 删除名帖字库
     */
//    @RequiresPermissions("system:card:remove")
    @Log(title = "名帖字库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(danmoFamousCardService.deleteDanmoFamousCardByIds(ids));
    }

    /**
     * 字帖首选次选择
     */
    @PostMapping("/selectFamousName")
    public Result<DanmoFamous> selectFamousName(@RequestBody DanmoFamousNameReq danmoFamousNameReq)
    {
       DanmoFamous danmoFamous = danmoFamousCardService.selectFamousName(danmoFamousNameReq);
        return success(danmoFamous);
    }
    /**
     * 查询某一个字帖跟关联的图片
     */
    @PostMapping("/selectFamousPicture")
    public Result selectFamousPicture(@RequestBody DanmoSelectFamousCarReq danmoSelectFamousCarReq)
    {
        List<DanmoFamous> danmoFamousPictureList= danmoFamousCardService.selectFamousPicture(danmoSelectFamousCarReq);
        return Result.success(danmoFamousPictureList);
    }

}
